package foodtable;

import java.util.List;

import com.andro.chansung.ConstantId;
import com.andro.chansung.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ADongFoodAdapter extends BaseAdapter {
	
	private List<FoodList> foodLists;
	private LayoutInflater inflater;
	private Context context;
	private ViewHolder viewHolder;
	
	private class ViewHolder {
		public TextView timeTv  = null;
		public TextView kindATv = null;
		public TextView kindBTv = null;
		public TextView kindCTv = null;
		public TextView kindDTv = null;
		public TextView kindETv = null;
		public TextView kindFTv = null;
	}
	
	public ADongFoodAdapter(Context context, List<FoodList> foodList) {
		this.context = context;
		this.foodLists = foodList;
		this.inflater = LayoutInflater.from(context);
	}
	
	public int getCount() {
		return foodLists.size();
	}

	public FoodList getItem(int position) {
		return foodLists.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		
		if( view == null ) {
			viewHolder = new ViewHolder();
			view = inflater.inflate(R.layout.a_dong_food_list_view_cell_layout, null);
			viewHolder.timeTv = (TextView)view.findViewById(R.id.a_dong_food_list_view_cell_time_tv);
			viewHolder.kindATv = (TextView)view.findViewById(R.id.a_dong_food_menu_kind_a_tv);
			viewHolder.kindBTv = (TextView)view.findViewById(R.id.a_dong_food_menu_kind_b_tv);
			viewHolder.kindCTv = (TextView)view.findViewById(R.id.a_dong_food_menu_kind_c_tv);
			viewHolder.kindDTv = (TextView)view.findViewById(R.id.a_dong_food_menu_kind_d_tv);
			viewHolder.kindETv = (TextView)view.findViewById(R.id.a_dong_food_menu_kind_e_tv);
			viewHolder.kindFTv = (TextView)view.findViewById(R.id.a_dong_food_menu_kind_f_tv);
			view.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder)view.getTag();
		}
		
		FoodList foodList = getItem(position);
		
		LinearLayout layoutB = (LinearLayout)view.findViewById(R.id.a_dong_food_table_kind_b_layout);
		LinearLayout layoutC = (LinearLayout)view.findViewById(R.id.a_dong_food_table_kind_c_layout);
		LinearLayout layoutD = (LinearLayout)view.findViewById(R.id.a_dong_food_table_kind_d_layout);
		LinearLayout layoutE = (LinearLayout)view.findViewById(R.id.a_dong_food_table_kind_e_layout);
		LinearLayout layoutF = (LinearLayout)view.findViewById(R.id.a_dong_food_table_kind_f_layout);
		
		layoutB.setVisibility(View.GONE);
		layoutC.setVisibility(View.GONE);
		layoutD.setVisibility(View.GONE);
		layoutE.setVisibility(View.GONE);
		layoutF.setVisibility(View.GONE);
		
		viewHolder.timeTv.setText(foodList.getFoods().get(0).getTime().toString());
		
		for( int i = 0; i < foodList.getFoods().size(); i++ ) {
			ConstantId.FOOD_KIND kind = foodList.getFoods().get(i).getKind();
			
			if( ConstantId.FOOD_KIND.직화.equals(kind) ) {
				layoutB.setVisibility(View.VISIBLE);
				viewHolder.kindBTv.setText(foodList.getFoods().get(i).getMenu());
			} else if( ConstantId.FOOD_KIND.일품.equals(kind) ) { 
				layoutC.setVisibility(View.VISIBLE);
				viewHolder.kindCTv.setText(foodList.getFoods().get(i).getMenu());
			} else if( ConstantId.FOOD_KIND.특식.equals(kind) ) {
				layoutD.setVisibility(View.VISIBLE);
				viewHolder.kindDTv.setText(foodList.getFoods().get(i).getMenu());
			} else if( ConstantId.FOOD_KIND.면류.equals(kind) ) {
				layoutE.setVisibility(View.VISIBLE);
				viewHolder.kindETv.setText(foodList.getFoods().get(i).getMenu());
			} else if( ConstantId.FOOD_KIND.일품식.equals(kind) ) {
				layoutF.setVisibility(View.VISIBLE);
				viewHolder.kindFTv.setText(foodList.getFoods().get(i).getMenu());
			} else {
				viewHolder.kindATv.setText(foodList.getFoods().get(i).getMenu());
			}
		}
		
		return view;
	}
}
